// pages/supervisionSite/index.js
//引入请求文件
var util = require('../../utils/util.js');
let app = getApp();
let url = app.url;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    superviseList: {},
	cardId: 0,
	stageTotal: [
		{
			picture: [],
			titleContent: '',
			detail: '',
			title: '阶段1'
		},
		{
			picture: [],
			titleContent: '',
			detail: '',
			title: '阶段2'
		},
		{
			picture: [],
			titleContent: '',
			detail: '',
			title: '阶段3'
		},
		{
			picture: [],
			titleContent: '',
			detail: '',
			title: '阶段4'
		},
		{
			picture: [],
			titleContent: '',
			detail: '',
			title: '阶段5'
		},
		{
			picture: [],
			titleContent: '',
			detail: '',
			title: '阶段6'
		},
		{
			picture: [],
			titleContent: '',
			detail: '',
			title: '阶段7'
		},
		{
			picture: [],
			titleContent: '',
			detail: '',
			title: '阶段8'
		},
		{
			picture: [],
			titleContent: '',
			detail: '',
			title: '阶段9'
		},
		{
			picture: [],
			titleContent: '',
			detail: '',
			title: '阶段10'
		},
		{
			picture: [],
			titleContent: '',
			detail: '',
			title: '阶段11'
		}
	]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 将父组件传递过来的参数保存在
		this.setData({
			cardId: options.cardId
		})
		// 渲染数据
		util(`${url}SupervisionSite/getSupervisionSiteDetail`, {id: this.data.cardId}).then(res=>{
			if (res.status == 1) {
				// 处理后端数据
				let obj = res.content;
				
				this.data.stageTotal[0].detail = obj.hydropower_detail;
				this.data.stageTotal[0].picture = obj.hydropower_picture;
				this.data.stageTotal[0].titleContent = obj.hydropower_introduce;
				
				this.data.stageTotal[1].detail = obj.carpentry_detail;
				this.data.stageTotal[1].picture = obj.carpentry_picture;
				this.data.stageTotal[1].titleContent = obj.carpentry_introduce;
				
				this.data.stageTotal[2].detail = obj.paint_detail;
				this.data.stageTotal[2].picture = obj.paint_picture;
				this.data.stageTotal[2].titleContent = obj.paint_introduce;
				
				this.data.stageTotal[3].detail = obj.check_detail;
				this.data.stageTotal[3].picture = obj.check_picture;
				this.data.stageTotal[3].titleContent = obj.check_introduce;
				
				this.data.stageTotal[4].detail = obj.detail5;
				this.data.stageTotal[4].picture = obj.picture5;
				this.data.stageTotal[4].titleContent = obj.introduce5;
				
				this.data.stageTotal[5].detail = obj.detail6;
				this.data.stageTotal[5].picture = obj.picture6
				this.data.stageTotal[5].titleContent = obj.introduce6;
				
				this.data.stageTotal[6].detail = obj.detail7;
				this.data.stageTotal[6].picture = obj.picture7;
				this.data.stageTotal[6].titleContent = obj.introduce7;
				
				this.data.stageTotal[7].detail = obj.detail8;
				this.data.stageTotal[7].picture = obj.picture8;
				this.data.stageTotal[7].titleContent = obj.introduce8;
				
				this.data.stageTotal[8].detail = obj.detail9;
				this.data.stageTotal[8].picture = obj.picture9;
				this.data.stageTotal[8].titleContent = obj.introduce9;
				
				this.data.stageTotal[9].detail = obj.detail10;
				this.data.stageTotal[9].picture = obj.picture10;
				this.data.stageTotal[9].titleContent = obj.introduce10;
				
				this.data.stageTotal[10].detail = obj.detail11;
				this.data.stageTotal[10].picture = obj.picture11;
				this.data.stageTotal[10].titleContent = obj.introduce11;
				
				this.data.stageTotal.forEach((item, index) => {
					if (item.picture === null) {
						item.picture = []
					} else if (typeof(item.picture) === 'string') {
						item.picture = item.picture.split(',')
					} else {
						item.picture = item.picture;
					}
				})
				
				this.setData({
					superviseList: obj,
					stageTotal: this.data.stageTotal
				})
				
				
			} else {
				wx.showToast({
					title: res.msg,
					icon: 'none'
				})
			}
		})
  },
	goSupervise(e){
    let supervisionid = e.currentTarget.dataset.supervisionid;
		wx.navigateTo({
      url: "/pages/supervisorEnroll/index?supervisionid=" + supervisionid
		})
	}
})